
package vista;
import java.awt.BorderLayout;

import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JLabel;

import javax.swing.JScrollPane;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.WindowConstants;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class VentanaConsultaProveedor extends javax.swing.JFrame {
	
	private JScrollPane scpTablaProveedor;
	private JTable tblProveedor;
	private JPanel pnlConsultaProveedor;
	private JLabel lblTitulo;
	private JLabel lblImagen;
	private JButton btnModificar;
	private JButton btnBuscar;
	private JButton btnEliminar;
	private JButton btnIncluir;
	
	
	public VentanaConsultaProveedor() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try{
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			BorderLayout thisLayout = new BorderLayout();
			getContentPane().setLayout(thisLayout);
			this.setTitle("Sistema de Almacen - Registro de Proveedores");
			{
				pnlConsultaProveedor = new JPanel();
				getContentPane().add(pnlConsultaProveedor, BorderLayout.CENTER);
				pnlConsultaProveedor.setLayout(null);
				pnlConsultaProveedor.setBounds(0, 0, 790, 377);
				pnlConsultaProveedor.setBackground(new java.awt.Color(255,255,255));
				{
					btnIncluir = new JButton();
					pnlConsultaProveedor.add(getLblImagen());
					pnlConsultaProveedor.add(btnIncluir);
					btnIncluir.setActionCommand("Incluir");
					btnIncluir.setIcon(new ImageIcon(getClass().getClassLoader().getResource("imagen/Boton_Incluir2.jpg")));
					btnIncluir.setBackground(new java.awt.Color(255,255,255));
					btnIncluir.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
					btnIncluir.setRolloverIcon((new ImageIcon(getClass().getClassLoader().getResource("imagen/Boton_Incluir.jpg"))));
					btnIncluir.setBounds(134, 312, 92, 34);

				}
				{
					btnEliminar = new JButton();
					pnlConsultaProveedor.add(btnEliminar);
					btnEliminar.setActionCommand("Eliminar");
					btnEliminar.setIcon(new ImageIcon(getClass().getClassLoader().getResource("imagen/Boton_Eliminar2.jpg")));
					btnEliminar.setBackground(new java.awt.Color(255,255,255));
					btnEliminar.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
					btnEliminar.setRolloverIcon((new ImageIcon(getClass().getClassLoader().getResource("imagen/Boton_Eliminar.jpg"))));
					btnEliminar.setBounds(264, 312, 92, 34);
				}
				{
					scpTablaProveedor = new JScrollPane();
					pnlConsultaProveedor.add(scpTablaProveedor);
					scpTablaProveedor.setBounds(91, 92, 457, 193);
					{
						TableModel tblProveedorModel = 
								new DefaultTableModel(
										new String[][] {  },
										new String[] { "Id","Nombre","Telefono","Correo","Direccion" });
						tblProveedor = new JTable();
						scpTablaProveedor.setViewportView(tblProveedor);
						tblProveedor.setModel(tblProveedorModel);
					}
				}
				{
					btnBuscar = new JButton();
					pnlConsultaProveedor.add(btnBuscar);
					btnBuscar.setText("Buscar");
					btnBuscar.setActionCommand("Buscar");
					btnBuscar.setBounds(273, 250, 103, 50);
					btnBuscar.setVisible(false);
				}
				{
					btnModificar = new JButton();
					pnlConsultaProveedor.add(btnModificar);
					pnlConsultaProveedor.add(getLblTitulo());
					btnModificar.setActionCommand("Modificar");
					btnModificar.setIcon(new ImageIcon(getClass().getClassLoader().getResource("imagen/Boton_Modifi2.jpg")));
					btnModificar.setBackground(new java.awt.Color(255,255,255));
					btnModificar.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
					btnModificar.setRolloverIcon((new ImageIcon(getClass().getClassLoader().getResource("imagen/Boton_Modifi.jpg"))));
					btnModificar.setBounds(393, 312, 92, 34);
				}
			}
			pack();
			this.setSize(627, 411);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	public void agregarListener(ActionListener accion) {

		btnEliminar.addActionListener(accion);
		btnIncluir.addActionListener(accion);
		btnBuscar.addActionListener(accion);
		btnModificar.addActionListener(accion);
	
	}

	

	public void mostrarMensaje(String mensaje) {
		JOptionPane.showMessageDialog(this, mensaje);
	}

	public int getCantidadFilasTbLinea() {
		return tblProveedor.getRowCount();
	}
	
	public int getCantidadColumnasTbLinea(){
		return tblProveedor.getColumnCount();
	}

	public void agregarFilaLinea(Vector<String> datoProveedor) {
		DefaultTableModel modelo = (DefaultTableModel) this.tblProveedor.getModel();

		modelo.addRow(datoProveedor);
		
	}
	
	public int getFilaSeleccionada(){
		
		return this.tblProveedor.getSelectedRow();
	}
	
	public void eliminarFilaSeleccionada(int i){
		
		DefaultTableModel modelo = (DefaultTableModel) this.tblProveedor.getModel();

		modelo.removeRow(i);
		
	}
	
	public void eliminarFilas(){
		DefaultTableModel modelo = (DefaultTableModel) this.tblProveedor.getModel();
		modelo.setRowCount(0);
	}
	
	public String obtenerCodigoProveedorFilaSeleccionada(){
		int fila = tblProveedor.getSelectedRow();
		String codProveedor = (String) tblProveedor.getModel().getValueAt(fila, 0);
		return codProveedor;
	}
	
	public int nroFilasSeleccionadas() {
		return tblProveedor.getSelectedRowCount();
	}
	
	public void setActionCommandModificar(String nombre){
		btnModificar.setActionCommand(nombre);
	}
	
	public void setActionCommandIncluir(String nombre){
		btnIncluir.setActionCommand(nombre);
	}
	
	public String getActionCommandModificar(){
		return btnModificar.getActionCommand();
	}
	
	public String getActionCommandIncluir(){
		return btnIncluir.getActionCommand();
	}
	
	private JLabel getLblImagen() {
		if(lblImagen == null) {
			lblImagen = new JLabel();
			lblImagen.setBounds(4, 34, 69, 377);
			lblImagen.setIcon(new ImageIcon(getClass().getClassLoader().getResource("imagen/fondo7.jpg")));
		}
		return lblImagen;
	}
	
	private JLabel getLblTitulo() {
		if(lblTitulo == null) {
			lblTitulo = new JLabel();
			lblTitulo.setText("Listado de Proveedores");
			lblTitulo.setBounds(226, 40, 223, 15);
			lblTitulo.setFont(new java.awt.Font("Bitstream Charter",0,18));
		}
		return lblTitulo;
	}
}
